package com.palfund.secondfragment;


import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

public class SecondActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i("SecondActivity", "---onCreate()--->First");
        setContentView(R.layout.activity_second);
        Log.i("SecondActivity", "---onCreate()--->Second");
        setTitle("SecondActivity");
        SecondFragment fragment = new SecondFragment();
        //FragmentManager fragmentManager = getSupportFragmentManager();
        android.app.FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.layout_container_second, fragment);
        transaction.commit();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i("SecondActivity", "---onRestart()--->");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.i("SecondActivity", "---onStart()--->");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.i("SecondActivity", "---onResume()--->");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.i("SecondActivity", "---onPause()--->");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.i("SecondActivity", "---onStop()--->");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i("SecondActivity", "---onDestroy()--->");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(Menu.NONE, 888, 2, "finish");
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case 888:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }


}
